package com.gj.spartprice.service.Impl;

import com.gj.spartprice.enumpackge.CurrencyEnum2;
import com.gj.spartprice.mapper.SpartPriceMapper;
import com.gj.spartprice.model.SpartPriceServiceVo;
import com.gj.spartprice.model.SpartPriceVo;
import com.gj.spartprice.model.CurrencyVo;
import com.gj.spartprice.service.SpartPriceService;
import com.gj.utli.AllRecords;
import com.gj.utli.ResultBuilderVo;
import com.gj.utli.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Tangyunhen on 2021-07-05.
 */
@Service
public class SpartPriceServiceImpl implements SpartPriceService{

    @Autowired
    private SpartPriceMapper spartPriceMapper;

    @Override
    public ResultVo queryPage(@Valid SpartPriceServiceVo spartPriceServiceVo) {
        //查询数据
       List<SpartPriceVo> spartPriceVoList= spartPriceMapper.queryDate(spartPriceServiceVo);
      /* for (SpartPriceVo spartPriceVo:spartPriceVoList){
           *//* if(factoryClassVo.getEnabled()==true){
              factoryClassVo.setEnabledName("启用");
            }else if (factoryClassVo.getEnabled()==false){
              factoryClassVo.setEnabledName("禁用");
            }*//*
            Boolean status = spartPriceVo.getStatus();
            Integer status2=status?1:0;
           spartPriceVo.setStatusName(StatusEnum2.getStatusName(status2));
        }*/
        int count=spartPriceMapper.queryCount(spartPriceServiceVo);
        AllRecords allRecords=new AllRecords();
        allRecords.setPageIndex(spartPriceServiceVo.getPageIndex());
        allRecords.setPageSize(spartPriceServiceVo.getPageSize());
        allRecords.resetTotalNumber(count);
        allRecords.setTotalNumber(count);
        allRecords.setDataList(spartPriceVoList);
        return ResultBuilderVo.success(allRecords);
    }

   /*@Override
    @Transactional //事务
    public ResultVo add(@Valid SpartPriceAddVo spartPriceAddVo) {
      SpartPriceVo spartPriceVo= spartPriceMapper.queryBylegalPersonCode(spartPriceAddVo.getLegalPersonCode());
        if (spartPriceVo!=null){
            return ResultBuilderVo.error("法人已经存在");
        }
        SpartPriceVo spartPriceVo1=new SpartPriceVo();
        BeanUtils.copyProperties(spartPriceAddVo,spartPriceVo1);
        Date nowDate=new Date();
        spartPriceVo1.setCreateName("大白");
        spartPriceVo1.setCreateTime(nowDate);
        spartPriceVo1.setUpdateName("小白");
        spartPriceVo1.setUpdateTime(nowDate);
        spartPriceMapper.insert(spartPriceVo1);
        return ResultBuilderVo.success();
    }*/

  /* @Override*/
  /*  public ResultVo getPullDownList() {
       //价格分类
      List<SpartPriceVo> spartPriceVoList= spartPriceMapper.querypriceClass();
//       //币别
       List<CurrencyVo> currencyVoList=new ArrayList<>();
        for (CurrencyEnum2 c: CurrencyEnum2.values()) {
            currencyVoList.add(new CurrencyVo(c.getcurrencyCode(),c.getcurrencyName()));
        }
        return null;
   }*/
}
